#ifdef MEMMAN_EXPORTS
#define MEMMAN_API __declspec(dllexport)
#else
#define MEMMAN_API __declspec(dllimport)
#endif

#define retbool return 0xFF & (int)

#include <vector>
#include "stdafx.h"
using namespace std;


class CMemMan {
public:
	CMemMan();
	~CMemMan();

	static enum Collections
	{
		Type,
		Service,
		Time,
		Message
	};

	void PushLine(char* data);
	unsigned PushBulk(char* data);
	unsigned GetEventsCountForThread(unsigned threadIdx);
	unsigned GetThreadIndex(short tid);
	unsigned GetThreadsCount();
	short GetTidForIndex(unsigned threadIdx);
	char* GetEventData(unsigned threadIdx, unsigned eventIdx, Collections colId);
	void ExpandEventMessage(char* msg, char* buffer);

private:
	void Clear();
	void DeleteCharPtrCol(vector<char*>* vect);
	void Init();
	char GetCharPtrColItemIndex(char* item, size_t sz, vector<char*>* vect);
	short GetCharPtrColItemIndexEx(char* item, size_t sz, vector<char*>* vect);
	char GetTypeFast(char* ptr);
	short Hex2Short(char* hex);
	char* PackLine(char* src);
	vector<char*>* GetDictionary(char one, char two);

	struct line
	{
		char Type;
		char Time[12];
		char Srv;
		char* Msg;
	};

	vector<short> *threads;	
	vector<char*> *srvs;
	vector<vector<line*>*> *globalCollection;

	vector<char*> *dictionary[256][256];
	CRITICAL_SECTION locks[256][256], lSrvs, lThreads;
	
	HANDLE _heap, _msgHeap;
	char threadsMax, threadsCount;
};
